﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebUI.BL.Contact;

namespace WebUI.AdminSite.Contact
{
    public partial class ContactManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                GetContactOnGrid();
            }
        }

        private void GetContactOnGrid()
        {
            ContactBL repository=new ContactBL();
            var dataSource = repository.GetContacs();
            grdContact.DataSource = dataSource.ToList();
            grdContact.DataBind();
        }

        protected void grdContact_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdContact.PageIndex = e.NewPageIndex;
            GetContactOnGrid();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //multi filter values
            string subject = txtSubject.Text.Trim();
            DateTime? frmDate = txtDatePickerFrom.Text.Trim()==""?null:(DateTime?)Convert.ToDateTime(txtDatePickerFrom.Text.Trim());
            DateTime? toDate = txtDatePickerTo.Text.Trim()==""?null:(DateTime?)Convert.ToDateTime(txtDatePickerTo.Text.Trim());
            if(subject!=""||frmDate!=null||toDate!=null)
            {
                ContactBL repository = new ContactBL();
                var dataSource = repository.GetContacsByMutltiFilter(subject, frmDate, toDate);
                grdContact.DataSource = dataSource.ToList();
                grdContact.DataBind();
            }
;        }
    }
}